package edu.upc.cineplanet.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import edu.upc.cineplanet.Domain.Cine;
import edu.upc.cineplanet.Domain.Funcion;
import edu.upc.cineplanet.Domain.Pelicula;
import edu.upc.cineplanet.service.CineService;
import edu.upc.cineplanet.service.FuncionService;
import edu.upc.cineplanet.service.PeliculaService;

@Controller
public class HomeController {

	@Autowired
	CineService service;
	
	@Autowired
	PeliculaService peliService;
	
	@Autowired
	FuncionService FunService;	

	@RequestMapping(value="/",method = RequestMethod.GET )	
	public String index(Model model){
		List<Cine> cines = service.obtenerCines(); 		
		model.addAttribute("data", cines);		
		return "home";
	}
	
	@RequestMapping(value="/",method = RequestMethod.POST )	
	public String setupForm1(@RequestParam("selCombo") String cine,Model model ) {
		List<Cine> cines = service.obtenerCines(); 				
		List<Funcion> funciones = FunService.verCartelera("09/04/2011", cine) ;
		model.addAttribute("data", cines);		
		model.addAttribute("data1", funciones);
		
        return "home";
    }						
	
	@RequestMapping(value="/busquedaPelicula",method = RequestMethod.GET )
	public String setupForm2(Model model ) {				
        return "busquedaPelicula";
    }
	
	@RequestMapping(value="/busquedaPelicula",method = RequestMethod.POST )
	public String setupForm3(@RequestParam("pelicula") String pelicula,Model model ) {		
		List<Pelicula> peliculas = peliService.buscarPeliculas("%"+pelicula+"%");
		model.addAttribute("data", peliculas);
        return "busquedaPelicula";
    }	
	
}
